package com.huike.contract.service.impl;

import com.huike.business.mapper.TbBusinessMapper;
import com.huike.clues.mapper.SysUserMapper;
import com.huike.clues.mapper.TbAssignRecordMapper;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.service.ISysUserService;
import com.huike.clues.service.ITbRulePoolService;
import com.huike.common.core.domain.entity.SysUser;
import com.huike.contract.domain.vo.TransferVo;
import com.huike.contract.service.TransferService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * @Author: fwh
 * @Date: 2023/07/13/22:31
 * @Description:
 */
@Service
public class TransferServiceImpl implements TransferService {

    @Resource
    private ISysUserService userService;
    @Resource
    private TbAssignRecordMapper assignRecordMapper;

    @Resource
    private ITbRulePoolService tbRulePoolService;

    @Resource
    private SysUserMapper sysUserMapper;

    @Resource
    private TbClueMapper clueMapper;

    @Resource
    private TbBusinessMapper businessMapper;


    /**
     * 获取转派列表
     *
     * @param sysUser
     * @return
     */
    @Override
    public List<TransferVo> selectTransferList(SysUser sysUser) {
        List<TransferVo> transferVoList = new ArrayList<>();
        List<SysUser> list=userService.selectUserList(sysUser);
        for (SysUser sysuser : list) {
            TransferVo transferVo = new TransferVo();
            int cluesNum = assignRecordMapper.countAssignCluesByUser(sysUser.getUserId());
            int businessNum = assignRecordMapper.countAssignBusinessByUser(sysUser.getUserId());
            if(cluesNum+businessNum>0){
                transferVo.setUserName(sysUser.getUserName());
                transferVo.setClueNum(cluesNum);
                transferVo.setBusinessNum(businessNum);
                transferVo.setUserId(sysUser.getUserId());
                transferVo.setPhonenumber(sysuser.getPhonenumber());
                transferVo.setCreateTime( sysuser.getCreateTime());
                transferVoList.add(transferVo);
            }
        }
        return transferVoList;
    }
}
